var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },


  onLoad: function (options) {
    var yz_id = options.id;
    this.setData({
      yz_id:yz_id
    })
    this.getYanzhiInfo();
  },

  getYanzhiInfo:function(){
    var t = this;
    app.visit("huodong/getYanzhiInfo", {
      yz_id:t.data.yz_id,
    }, "", function(c) {
      console.log(c)
      if(0 == c.code){
        t.setData({
          info:c.data,
          level_start:c.data.level_start,
          level_end:c.data.level_end,
          discount:c.data.discount
        })
      }else{
        app.showToast(c.msg)
      }
    })
  },

  setStart:function(e){
    this.setData({
      level_start:e.detail.value
    })
  },

  setEnd:function(e){
    this.setData({
      level_end:e.detail.value
    })
  },

  setDiscount:function(e){
    this.setData({
      discount:e.detail.value
    })
  },

  tijiao:function(e){
    var t = this;
    if (!(/(^[0-9]+(.[0-9]{1,2})?$)/.test(t.data.level_start))) {
      app.myToast("所猜价格只能输入数字！")
    }else if (!(/(^[0-9]+(.[0-9]{1,2})?$)/.test(t.data.level_end))) {
      app.myToast("所猜价格只能输入数字！")
    }else if (!(/(^[0-9]+(.[0-9]{1,2})?$)/.test(t.data.discount))) {
      app.myToast("所猜价格只能输入数字！")
    }else{
      app.visit("huodong/setYanzhiInfo", {
        yz_id:t.data.yz_id,
        level_start:t.data.level_start,
        level_end:t.data.level_end,
        discount:t.data.discount
      }, "", function(c) {
        console.log(c)
        if(0 == c.code){
          wx.showToast({
            title: '修改成功',
            icon: 'none',
            success: function () {
              wx.navigateBack();
            }
          })
        }else{
          app.showToast(c.msg)
        }
      })
    }
  },

})